home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 2.1 KB | 119 lines | [TEXT/CWIE] |
- // Focus.cp
-
- #ifndef Focus_h
- #include "Focus.h"
- #endif
- #ifndef ListLoop_h
- #include "ListLoop.h"
- #endif
- #ifndef Activator_h
- #include "Activator.h"
- #endif
-
- Focus::Focus()
- : parent( 0 ),
- favoredChild( 0 ),
- children( 0 ),
- active( false )
- {
- }
-
- Focus::Focus( Below, Focus& theParent )
- : parent( &theParent ),
- favoredChild( 0 ),
- children( 0 ),
- active( false )
- {
- Assert( theParent.children < maxuint32 );
- theParent.children++;
- if ( theParent.favoredChild == 0 && !theParent.active )
- theParent.favoredChild = this;
- }
-
- Focus::~Focus()
- {
- Assert( !active );
- Assert( children == 0 );
- Assert( favoredChild == 0 );
-
- if ( parent != 0 )
- {
- Assert( parent->children > 0 );
- parent->children--;
- if ( parent->favoredChild == this )
- parent->favoredChild = 0;
- }
- }
-
- void Focus::FavorNoChild()
- {
- if ( favoredChild == 0 )
- return;
-
- if ( active )
- favoredChild->Deactivate();
-
- favoredChild = 0;
- }
-
- void Focus::FavorChild( Focus& newFavorite )
- {
- Assert( newFavorite.parent == this );
- if ( favoredChild == &newFavorite )
- return;
-
- if ( active && favoredChild != 0 )
- favoredChild->Deactivate();
-
- favoredChild = &newFavorite;
-
- if ( active )
- newFavorite.Activate();
- }
-
- void Focus::Activate()
- {
- Assert( !active );
- Assert( parent == 0 || parent->active );
- Assert( parent == 0 || parent->favoredChild == this );
-
- active = true;
-
- for ( ListLoop<Activator> a( activators ); a.Unfinished(); a++ )
- a->FocusActivated();
-
- if ( favoredChild != 0 )
- favoredChild->Activate();
- }
-
- void Focus::Deactivate()
- {
- Assert( active );
- Assert( parent == 0 || parent->active );
- Assert( parent == 0 || parent->favoredChild == this );
-
- if ( favoredChild != 0 )
- favoredChild->Deactivate();
-
- active = false;
-
- for ( ListLoop<Activator> a( activators, atEnd ); a.Unfinished(); a-- )
- a->FocusDeactivated();
- }
-
- void Focus::BeFavored()
- {
- Assert( parent != 0 );
- parent->FavorChild( *this );
- }
-
- void Focus::BeDisfavored()
- {
- Assert( parent != 0 );
- if ( parent->FavoredChild() == this )
- parent->FavorNoChild();
- }
-
- #include "ListOf.cp"
- #include "ListLoop.cp"
-